import { ApigetDutyDoctor  } from "../../../api/index"
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    loading: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getList()
  },
  
  goMessageRoom(e) {
    const item = e.currentTarget.dataset.item
    const ops = {
      icon: item.icon,
      doctor_id: item.id,
      doctor_name: item.name,
      department_name: item?.department?.name ?? "",
      position: item.position,
    }
    wx.navigateTo({
      url: '/pages/visit/message/index?contact=' + JSON.stringify(ops),
    })
  },

  getList() {
    this.setData({
      loading: true
    })
    ApigetDutyDoctor().then(res => {
      this.setData({
        list: res.data.map(item => {
          item.icon = app.setPath(item.icon,true)
          return item
        })
      })
    }).finally(_=>{
      this.setData({
        loading: false
      })
    })
  },

  onGoDetail(e) {
    wx.setStorageSync('doctorPage', e.currentTarget.dataset.item)
    wx.navigateTo({
      url: '/pages/visit/doctorPage/index',
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})